'use strict';

angular.module('app').controller('maintenanceGroupController', [ '$rootScope', '$scope', '$http', '$state','toaster','$modal',
    function($rootScope, $scope, $http, $state,toaster,$modal) {
        $scope.title = '维修人员组';
        $scope.param = {};
        $scope.search = function () {
        	console.log($scope.param);
            $scope.loading = true;
            if($scope.pageFlag != 1){
                $scope.param.pageNum=1;
            }else{
                $scope.pageFlag = 2;
            }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : '/dac/dm/DmMaintain/groupList',
                data: angular.toJson($scope.param)
            }).then(function(result) {
                $scope.loading = false;
                //console.log(result)
                if (result.httpCode == 200) {
                    $scope.pageInfo = result;
                } else {
                    toaster.clear('*');
                    toaster.pop('error','', result.msg)
                }
                $scope.$apply();
            });
        }
        $scope.search();
        
        //禁用启用
        $scope.changeStatus = function(groupCode,status){
        	//console.log(groupCode,status); 
        	$scope.param = { };
        	$scope.param.groupCode = groupCode;
			if(status=='1'){//如果是启用状态，就变为禁用
			    $scope.param.status = '2'
			}else if(status=='2'){
				$scope.param.status = '1'
			}
        	$.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : '/dac/dm/DmMaintain/updateGroup',
                data: angular.toJson($scope.param)
            }).then(function(result) {
                $scope.loading = false;
               // console.log(result)
                if (result.httpCode == 200) {
                    $scope.search();
                } else {
                    toaster.clear('*');
                    toaster.pop('error','', result.msg)
                }
                $scope.$apply();
            });
        }
        //查询
        $scope.clearSearch = function() {
			$scope.param.keyword= null;
			$scope.search();
		}
        // 翻页
        $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.pageFlag = 1;//将开关值设置为1
            $scope.search();
        };

    } ]);
